function nberdates_ajd(s)
% This is the same code as NBERDATES.m by F. Velde. 
% Just changing the recession dates to those in NBERDATES_SAMP 
%NBERDATES   adds NBER recession dates to a graph
%   NBERDATES('s') adds stripes to a graph to indicate recessions
%   based on the NBER beginnings and ends of recessions (monthly,
%   1945 to 201).  The color of the stripes is given by the string
%   's' (default is yellow if 's' is omitted).
% 
% Francois Velde 1998/2004/2008
% 
% extend back to 1884 using Romer JEH 1994 

if nargin == 0 | nargin > 1 | (nargin ==1 & (~isstr(s) | isempty(s) ) )
   color='y';
else
   valid_colors = 'ymrgbwkc'; % and don't forget c followed by an integer
   color = 'y';
   % Look for color
   [aa,c] = meshgrid(s,valid_colors);
   [kr,kc] = find(aa==c);
   if ~isempty(kc), % found a color
      kc = min(kc);
      color = s(kc);
      if color == 'c' & kc<length(s), % Check for c followed by integer
         d = s(kc+1:end) >= '0' & s(kc+1:end) <= '9';
         d = find(d(1:min(length(d),2)));
         if ~isempty(d), color = [color s(d+kc)]; end
      end
   end
end

nberrd=[...
      1887+1/12
   1887+6/12
   1893
   1894+1/12
   1896
   1897
   1900+3/12
   1900+11/12
   1903+6/12
   1904+2/12
   1907+6/12
   1908+5/12
   1910
   1911+4/12
   1914+5/12
   1914+11/12
   1916+4/12
   1917
   1918+6/12
   1919+2/12
   1920
   1921+2/12
   1923+4/12
   1924+6/12
   1927+2/12
   1927+11/12
   1929+8/12
   1932+6/12
   1937+7/12
   1938+5/12
   %1939+11/12
   %1940+2/12
1945+1/12
1945+9/12
1948+10/12
1949+9/12
1953+6/12
1954+4/12
1957+7/12
1958+3/12
1960+3/12
1961+1/12
1969+11/12
1970+10/12
1973+10/12
1975+2/12
1980+0/12
1980+6/12
1981+6/12
1982+10/12
1990+6/12
1991+2/12
2001+2/12

2001+10/12

2007+11/12
2009+9/12];


% disp('Change End 2001 recession '); 
% pause(1); 
% 2001+10/12    Original Date 


% freeze the graph
hold on;
thisgraph=gca;
%nberch=get(thisgraph,'Children');
nberxlim=get(thisgraph,'XLim');
nberylim=get(thisgraph,'YLim');
% put the shaded areas for recessions
nbernr=length(nberrd)/2;
for nberi=1:nbernr
%   nberh=patch('XData',[nberrd(2*(nberi-1)+1) nberrd(2*(nberi-1)+1) nberrd(2*(nberi-1)+2) nberrd(2*(nberi-1)+2)],'YData',[nberylim(1) nberylim(2) nberylim(2) nberylim(1)],'FaceColor',color);
    nberh=surf([nberrd(2*(nberi-1)+1) nberrd(2*(nberi-1)+2)],[nberylim(1) nberylim(2)],-ones(2,2));
    set(nberh,'EdgeColor','none','FaceColor',color);
%   set(nberh,'FaceAlpha',0.25); % this causes Matlab to crash
end
if floor(nbernr)<nbernr % are we in a recession?
   % how far does the data go?
   childd=get(gca,'Children');
   xmax=nberxlim(1);
   for j=1:length(childd)
      if strcmp(get(childd(j),'Type'),'line')
         xmax1=max(get(childd(j),'XData'));
         xmax=max([xmax xmax1]);
      end
   end
   %nberh=patch('XData',[nberrd(length(nberrd)) nberrd(length(nberrd)) xmax xmax],'YData',[nberylim(1) nberylim(2) nberylim(2) nberylim(1)],'FaceColor',color);
   nberh=surf([nberrd(length(nberrd)) xmax],[nberylim(1) nberylim(2)],-ones(2,2));
   set(nberh,'EdgeColor','none','FaceColor',color);
%   set(nberh,'FaceAlpha',0.25); % this causes Matlab to crash
end

set(thisgraph,'Layer','top','XLim',nberxlim,'YLim',nberylim,'View',[0 90])



%return
%%% this doesn't work anymore, so I set the transparency of the yellow
%%% patches instead (FRV 01/17/08)
% % now redraw the graph
% for nberi=1:length(nberch)
%    set(nberch,'Visible','off');
%    nberv=get(nberch(nberi));
%    nberstr=nberv.Type;
%    if  strcmp(nberstr,'line')
%       h=line(rmfield(nberv,char('Type','BeingDeleted')));
%       set(h,'Visible','on')
%    elseif strcmp(nberstr,'patch')
%       h=patch(rmfield(nberv,char('Type','BeingDeleted')))      
%       set(h,'Visible','on')
%    elseif strcmp(nberstr,'text')
%       h=text(rmfield(rmfield(nberv,char('Type','BeingDeleted')),'Extent'));
%       set(h,'Visible','on')
%    end
% end


